const { goodsFormatError } = require("../constant/error");
const Parameter = require("parameter");
const parameter = new Parameter();

const validator = async (ctx, next) => {
  try {
    parameter.validate(
      {
        goods_name: { type: "string", required: true },
        goods_price: { type: "number", required: true },
        goods_img: { type: "string", required: true },
        deal_count: { type: "string", required: true}
      },
      ctx.request.body
    );
  } catch (err) {
    return ctx.app.emit("error", goodsFormatError, ctx);
  }

  await next();
};

module.exports = {
  validator,
};
